﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Work.BL.Managers;
using Work.BL.POCOs;
using Work.DAL.Hibernate.Abstract;
using Work.DAL.Hibernate.Entities;
using Work.Tools.ObjectMapper;

namespace Work.BL.Hibernate.Managers
{
    public class HExpirianceManager : IExpirianceManager
    {
        #region Fields

        private readonly ICWSessionFactory _sessionFactory;
        private readonly IObjectMapper _objectMapper;

        #endregion

        #region Constructors

        public HExpirianceManager(ICWSessionFactory sessionFactory, IObjectMapper objectMapper)
        {
            this._sessionFactory = sessionFactory;
            this._objectMapper = objectMapper;
        }

        #endregion

        #region IEducationManager Members

        public ExpiriancePOCO Insert(ExpiriancePOCO expiriancePoco)
        {
            using (ISession session = this._sessionFactory.CreateSession())
            {
                Expiriance expiriance = _objectMapper.Map<ExpiriancePOCO, Expiriance>(expiriancePoco);
                session.Save(expiriance);
                session.Flush();
                return _objectMapper.Map<Expiriance, ExpiriancePOCO>(expiriance);
            }
        }

        #endregion
    }
}
